#include "IDPool.h"

IDPool::IDPool(int minID,int maxID)
{
	this->minID = minID;
	this->maxID = maxID;
	this->curID = minID;
}

int IDPool::getID()
{
	if(curID<maxID)
	{
		return curID++;
	}
	else
	{
		if(!freeIDs.empty())
		{
			int id = freeIDs.front();
			freeIDs.pop_front();
			return id;
		}
		else
		{
			return -1;
		}
	}
}

bool IDPool::freeID(int id)
{
	if(id>maxID || id<minID)
	{
		return false;
	}
	freeIDs.push_back(id);
	return true;
}
